package array;

import java.util.Arrays;

/**
 * Created by fengliejv on 2017/10/16.
 */
public class MajorityElement169 {
    public int majorityElement(int[] nums) {
        if(nums==null||nums.length==0){
            return -1;
        }
        int count = 1;
        int num = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if(nums[i]==num){
                count++;
            }else {
                if(count>0){
                    count--;
                }else {
                    num = nums[i];
                    count++;
                }
            }
        }
        return num;
    }

}
